using UnityEngine;
using System.Collections;

/// \class gkInitialDepthInGameVolume
/// \brief constraint the actor to a certain depth relative of the game volume depth
[AddComponentMenu("GK/Engine/Game/Spawn/gkInitialDepthInGameVolume")]
public class gkInitialDepthInGameVolume : MonoBehaviour 
{
    /// The depth in game volume depth percent
    public float PercentDepth;

    /// \brief  Called just after the game begin to play
    void Start()
    {
	    Bounds oGameVolumeBoudingBox;
	    Vector3 f3OwnerPosition;

        // Get the spawning volume bounding box
        gkUtilityBounds.GrabColliderOrRendererBounds(GameObject.Find("GameVolume"), out oGameVolumeBoudingBox);

	    // Set the depth of the owner
	    f3OwnerPosition = transform.position;
	    f3OwnerPosition.z = oGameVolumeBoudingBox.min.z 
		    + ( (PercentDepth + 1.0f) * 0.5f)* (oGameVolumeBoudingBox.max.z - oGameVolumeBoudingBox.min.z);
	    transform.position = f3OwnerPosition;
    }
}
